/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pthing.hpp - PegThing basic PEG GUI object class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
// This class identifies the base functionality inherited by all GUI objects.
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGTHING_
#define _PEGTHING_

class PegPresentationManager;        // forward references;

class PegThing
{
    friend class TargetScreenWin;   // for WindowBuilder only
    friend class PegPresentationManager;
 
    public:

        PegThing(const PegRect &Rect, PEGUSHORT Id = 0,
                 PEGULONG Style = FF_NONE);

        PegThing(PEGUSHORT Id = 0, PEGULONG Style = FF_NONE);

        virtual ~PegThing();

        virtual void Add(PegThing *pWhat, PEGBOOL DoShow = TRUE);
        virtual void AddStatus(PEGULONG OrVal) {mStatus |= OrVal;}
        virtual void AddStyle(PEGULONG OrVal) {mStyle |= OrVal;}
        virtual void AddToEnd(PegThing *pWhat, PEGBOOL DoShow = TRUE);

       #ifdef PEG_ARC_GRAPHICS
        inline void Arc(PEGINT xc, PEGINT yc, PEGINT XRadius, PEGINT YRadius,
            PEGINT start_angle, PEGINT end_angle, PegBrush &Brush,
            PEGINT width = 1)
        {
            Screen()->Arc(xc, yc, XRadius, YRadius, start_angle, end_angle,
                Brush, width);
        }
       #endif
       
        inline PEGINT BeginDraw(const PegRect &Invalid)
            {
                return (Screen()->BeginDraw(this, Invalid, mSurface));
            }

        inline PEGINT BeginDraw(const PegRect &Invalid, PEGINT Surface)
            {
                return (Screen()->BeginDraw(this, Invalid, Surface));
            }

        inline void Bitmap(PegPoint Where, PegBitmap *pGetmap)
        {
            Screen()->Bitmap(Where, pGetmap);
        }

        inline void Bitmap(PegPoint Where, PEGUINT BitmapId)
        {
            Screen()->Bitmap(Where, PegResourceManager::GetBitmap(BitmapId));
        }

        inline void BitmapFill(PegRect &Rect, PegBitmap *pGetmap)
        {
            Screen()->BitmapFill(Rect, pGetmap);
        }

        void CapturePointer(void);
        virtual void Center(PegThing *pWhat);
        virtual PegPoint CenterOf(PegThing *pWhat);

       #if defined(PEG_KEYBOARD_SUPPORT) && defined(PEG_ARROW_KEY_SUPPORT)
        virtual PEGBOOL CheckDirectionalMove(PEGINT Key);
       #endif

        PEGBOOL CheckSendSignal(PEGUBYTE Signal);

       #ifdef PEG_ARC_GRAPHICS
        inline void Circle(PEGINT xCenter, PEGINT yCenter, PEGINT radius,
                           PegBrush &Brush)
        {
            Screen()->Circle(xCenter, yCenter, radius, Brush);
        }
       #endif   // PEG_FULL_GRAPHICS

        virtual PEGBOOL Contains(const PegPoint &Spot)
        {
            return mClip.Contains(Spot);
        }

       #ifdef PEG_KEYBOARD_SUPPORT
        virtual PEGINT DefaultKeyHandler(const PegMessage &InMesg);
       #endif

        void Destroy(PegThing *pWhat);

        PEGLONG Distance(PegPoint p1, PegPoint p2);


        virtual void Draw(const PegRect &Invalid);
        virtual void DrawChildren(const PegRect &Invalid);

        inline void DrawText(PegPoint Where, const PEGCHAR *pText,
                             PegBrush &Brush, const PegFont *pFont, 
                             PEGINT Count = -1)
        {
            Screen()->DrawText(Where, pText, Brush, pFont, Count);
        }

        inline void DrawText(PegPoint Where, const PEGCHAR *pText,
                             PegBrush &Brush, PEGUINT FontId, 
                             PEGINT Count = -1)
        {
            Screen()->DrawText(Where, pText, Brush,
                    PegResourceManager::GetFont(FontId), Count);
        }

        inline void EndDraw(void)  {Screen()->EndDraw();}
        virtual PegThing *Find(PEGUSHORT Id, PEGBOOL Recursive = TRUE);


       #if defined(PEG_KEYBOARD_SUPPORT) && defined(PEG_ARROW_KEY_SUPPORT)
        virtual PegThing *FindNearestNeighbor(PEGINT Key,
                                              PegThing *pStart, 
                                              PegPoint Center);
        PegThing *FindNearestNeighbor(PegThing *pStart, PEGLONG *pPutDist, 
                                      PEGINT Key, PegPoint CenterThis, 
                                      PEGBOOL Loose);
       #endif   // PEG_ARROW_KEY_SUPPORT


        PegThing *First (void) const {return mpFirst;}

        PEGUSHORT FrameStyle(void) {return ((PEGUSHORT) (mStyle & FF_MASK));}

        void FrameStyle(PEGULONG Style)
        {
            mStyle &= ~FF_MASK;
            AddStyle(Style);
        }

        virtual PEGUINT GetColor(const PEGUBYTE Index);

        PEGUSHORT GetId(void) {return mId;}

        PEGUSHORT GetSignals(void) {return mSignalMask;}

        PEGULONG GetStatus(void) {return mStatus;}

        virtual PEGULONG GetStyle(void) {return mStyle;}

       #if defined(PEG_VIEWPORTS)
        Viewport *GetViewportList(void) { return mpViewportList; }        
       #endif

        void Hide(PegThing *pChild);

        void InitClient(void);

        void Invalidate(const PegRect &Rect);
        
        inline void Invalidate(void)
        {
            Invalidate(mReal);
        }

        PEGBOOL IsDescendentOf(PegThing *pParent);

        virtual void KillFocus(PegThing *);

        inline void KillTimer(PEGUSHORT Id)
        {
            TimerManager()->KillTimer(this, Id);
        }

        inline void Line(PEGINT XStart, PEGINT YStart, PEGINT XEnd, 
                         PEGINT YEnd, PegBrush &Brush)
        {
            Screen()->Line(XStart, YStart, XEnd, YEnd, Brush);
        }

        virtual PEGINT Message(const PegMessage &Mesg);

        void MessageChildren(const PegMessage &Mesg);

        static PegMessageQueue *MessageQueue() {return mpMessageQueue;}

        virtual void MoveFocusToFirstClientChild(void);

        virtual void MoveToFront(PegThing *pWhat);

        PegThing *Next (void) const {return mpNext;}


       #if defined(PEG_KEYBOARD_SUPPORT) && defined(PEG_TAB_KEY_SUPPORT)
        PegThing *NextTabLink(void);
       #endif

        PegThing *Parent (void) const {return mpParent;}

        virtual void ParentShift(PEGINT x, PEGINT y);

        static PegPresentationManager *Presentation() {return mpPresentation;}

        PegThing *Previous(void) const {return mpPrev;}

       #if defined(PEG_KEYBOARD_SUPPORT) && defined(PEG_TAB_KEY_SUPPORT)
        PegThing *PrevTabLink(void);
       #endif

       #ifdef PEG_PRINTER_SUPPORT
        static PegPrinter *Printer() {return mpPrinter;}
       #endif

        inline void Rectangle(const PegRect &Rect, PegBrush &Brush)
        {
            Screen()->Rectangle(Rect, Brush);
        }

        inline PEGBOOL RectMove(PegRect Get, PegRect ClipTo,
                                PEGINT xShift, PEGINT yShift)
        {
            return (Screen()->RectMove(Get, ClipTo, xShift, yShift));
        }

        void ReleasePointer(void);

        virtual PegThing *Remove(PegThing *pWhat);

        virtual void RemoveStatus(PEGULONG AndVal) {mStatus &= ~AndVal;}

        virtual void RemoveStyle(PEGULONG AndVal) {mStyle &= ~AndVal;}

        virtual void Resize(const PegRect &Size);

        static PegScreen *Screen() {return mpScreen;}

        virtual void SendSignal(PEGUBYTE Signal);

        virtual void SetColor(const PEGUBYTE Index, const PEGUINT ColorId);

        void SetId(PEGUSHORT Id) {mId = Id;}

       #if defined(PEG_KEYBOARD_SUPPORT) && defined(PEG_TAB_KEY_SUPPORT)
        void SetDefaultTabLinks(void);
       #endif

        static void SetMessageQueuePtr(PegMessageQueue *pq)
        {
            mpMessageQueue = pq;
        }

       #if defined(PEG_MOUSE_SUPPORT)
        inline void SetPointerType(PEGUINT Type)
        {
            Screen()->SetPointerType(Type);
        }
       #else
        inline void SetPointerType(PEGUINT Type) {Type = Type;}
       #endif

        static void SetPresentationManagerPtr(PegPresentationManager *pm)
        {
            mpPresentation = pm;
        }

       #if defined(PEG_PRINTER_SUPPORT)
        static void SetPrinterPtr(PegPrinter *pPrinter)
        {
            mpPrinter = pPrinter;
        }
       #endif

        static void SetScreenPtr(PegScreen *ps) {mpScreen = ps;}

        void SetSignals(PEGUSHORT Mask) {mSignalMask = Mask;}

        void SetSignals(PEGUSHORT Id, PEGUSHORT Mask)
        {
            mId = Id;
            mSignalMask = Mask;
        }

        virtual void SetStyle(PEGULONG Style) {mStyle = Style;}

       #if defined(PEG_KEYBOARD_SUPPORT) && defined(PEG_TAB_KEY_SUPPORT)
        void SetTabLink(PegThing *pNext) {mpTabLink = pNext;}
        void SetTabOrder(PEGUSHORT *pIds);
       #endif

        void SetSurface(PEGINT Surface, PEGBOOL bRecursive = TRUE);

        inline void SetTimer(PEGUSHORT Id, PEGLONG Count, PEGLONG Reset)
        {
            TimerManager()->SetTimer(this, Id, Count, Reset);
        }

        static void SetTimerManager(PegTimerManager *ps) {mpTimerManager = ps;}

       #ifdef PEG_TOUCH_SUPPORT
        static void SetTouchDevice(PegInputDevice *td) {mpTouchDevice = td;}
       #endif

       #ifdef PEG_KEYBOARD_SUPPORT
        static void SetKeyboardDevice(PegInputDevice *kd) {mpKeyboardDevice = kd;}
       #endif

       #ifdef PEG_MOUSE_SUPPORT
        static void SetMouseDevice(PegInputDevice *md) {mpMouseDevice = md;}
       #endif

        PEGBOOL Show(PegThing *pWhat);

        void StandardBorder(PEGUINT ColorId);

        PEGBOOL  StatusIs(PEGULONG Mask);

        inline PEGSHORT TextHeight(PEGUINT FontId)
        {
            return Screen()->TextHeight(FontId);
        }

        inline PEGSHORT TextHeight(const PegFont *pFont)
        {
            return Screen()->TextHeight(pFont);

        }

        inline PEGSHORT TextWidth(const PEGCHAR *pText, PEGUINT FontId)
        {
            return Screen()->TextWidth(pText, FontId);
        }

        inline PEGSHORT TextWidth(const PEGCHAR *pText, const PegFont *pFont)
        {
            return Screen()->TextWidth(pText, pFont);
        }

        static PegTimerManager *TimerManager(void) {return mpTimerManager;}

       #ifdef PEG_TOUCH_SUPPORT
        static PegInputDevice *TouchDevice() { return mpTouchDevice;}
       #endif

       #ifdef PEG_KEYBOARD_SUPPORT
        static PegInputDevice *KeyboardDevice() { return mpKeyboardDevice;}
       #endif

       #ifdef PEG_MOUSE_SUPPORT
        static PegInputDevice *MouseDevice() { return mpMouseDevice;}
       #endif

        PEGUSHORT Type(void) { return mType; }

        void Type(PEGUSHORT Set) {mType = Set;}
        void UpdateChildClipping(void);

        const PEGCHAR *Version(void);
        
        PEGINT mSurface;
        PegRect mReal;
        PegRect mClient;
        PegRect mClip;
        PEGUINT  mColorId[4];

    protected:

        PegThing *mpFirst;
        PegThing *mpNext;
        PegThing *mpParent;
        PegThing *mpPrev;

       #if defined(PEG_VIEWPORTS)
        Viewport *mpViewportList;
       #endif

       #ifdef PEG_PRINTER_SUPPORT
        static PegPrinter *mpPrinter;
       #endif

       #if defined(PEG_KEYBOARD_SUPPORT) && defined(PEG_TAB_KEY_SUPPORT)
        PegThing *mpTabLink;
       #endif

        static PegMessageQueue *mpMessageQueue;

        static PegPresentationManager *mpPresentation;

        static PegScreen *mpScreen;

        static PegTimerManager *mpTimerManager;

       #ifdef PEG_TOUCH_SUPPORT
        static PegInputDevice *mpTouchDevice;
       #endif

       #ifdef PEG_KEYBOARD_SUPPORT
        static PegInputDevice *mpKeyboardDevice;
       #endif

       #ifdef PEG_MOUSE_SUPPORT
        static PegInputDevice *mpMouseDevice;
       #endif

        PEGULONG  mStyle;
        PEGULONG  mStatus;

        PEGUSHORT mId;
        PEGUSHORT mSignalMask;
        PEGUSHORT mType;
};



#endif

// End of file


